plot_type <- function(data_dt,type,title,xaxis){
  size <- c("64x64","512x512","1024x1024","2048x2048","4096x4096","8192x8192")
  proc <- c("8","16","32","64")
  
  if(xaxis == "Size")
  {
    p <- ggplot(data_dt[Type == type,],aes(x=factor(Data,levels = unique(Data)),y=Time,group = Node,colour = Node)) + 
      geom_point() + geom_line(stat = "identity",size =1) + facet_wrap(~factor(Processes,levels = unique(Processes))) +
      labs(x = "Size of Input", y = "Time (s)") + 
      theme(axis.text.x = element_text(angle = 45, hjust = 1),legend.title = element_blank()) + 
      scale_y_continuous(breaks = seq(min(data_dt[Type == type,]$Time),max(data_dt[Type == type,]$Time) + 5,by=5)) +
      ggtitle(title)
    
    for(i in proc)
    {
      print(ggplot(data_dt[Type == type & Processes == i,],aes(x=factor(Data,levels = unique(Data)),y=Time,group = Node,colour = Node)) + 
              geom_point() + geom_line(stat = "identity",size =1) +
              labs(x = "Size of Input", y = "Time (s)") + 
              theme(axis.text.x = element_text(angle = 45, hjust = 1),legend.title = element_blank()) + 
              ggtitle(paste0(title," ,#Processes - ",i)))
    }
  }
  else if(xaxis == "Processes")
  {
    p <- ggplot(data_dt[Type == type,],aes(x=factor(Processes,levels = unique(Processes)),y=Time,group = Node,colour = Node)) + 
      geom_point() + geom_line(stat = "identity",size =1) + facet_wrap(~factor(Data,levels = unique(Data))) +
      labs(x = "#Processes", y = "Time (s)") + 
      theme(axis.text.x = element_text(angle = 45, hjust = 1),legend.title = element_blank()) + 
      scale_y_continuous(breaks = seq(min(data_dt[Type == type,]$Time),max(data_dt[Type == type,]$Time) + 5,by=5)) +
      ggtitle(title)
    
    for(i in size)
    {
      print(ggplot(data_dt[Type == type & Data == i,],aes(x=factor(Processes,levels = unique(Processes)),y=Time,group = Node,colour = Node)) + 
              geom_point() + geom_line(stat = "identity",size =1) +
              labs(x = "#Processes", y = "Time (s)") + 
              theme(axis.text.x = element_text(angle = 45, hjust = 1),legend.title = element_blank()) + 
              ggtitle(paste0(title," ,Size of Input - ",i)))
    }
  }
  
  
  return(p)
}
library(readxl)
library(data.table)
library(tidyr)
library(ggplot2)

hw_baseline <- read_excel(paste0("~/Desktop/TUM WS18/Programming of Supercomputer/Assignment4/assign4/plot/hw_","baseline",".xlsx"),col_names = T)

hw_collective <- read_excel(paste0("~/Desktop/TUM WS18/Programming of Supercomputer/Assignment4/assign4/plot/hw_","collective",".xlsx"),col_names = T)

hw_io <- read_excel(paste0("~/Desktop/TUM WS18/Programming of Supercomputer/Assignment4/assign4/plot/hw_","io",".xlsx"),col_names = T)


hw_tidy <- gather(hw_baseline,key = "Processes",value = "Time",-c("Data","Type"))

hw_ctidy <- gather(hw_collective,key = "Processes",value = "Time",-c("Data","Type"))

hw_itidy <- gather(hw_io,key = "Processes",value = "Time",-c("Data","Type"))


hw_b_dt <- as.data.table(hw_tidy)

hw_c_dt <- as.data.table(hw_ctidy)

hw_i_dt <- as.data.table(hw_itidy)


hw_b_dt[,"Time"] <- round(hw_b_dt$Time,2)

hw_c_dt[,"Time"] <- round(hw_c_dt$Time,2)

hw_i_dt[,"Time"] <- round(hw_i_dt$Time,2)



hw_b_dt[,Node := "Haswell @Baseline"]

hw_c_dt[,Node := "Haswell @Collective"]

hw_i_dt[,Node := "Haswell @Parallel IO"]



data_dt1 <- rbind(hw_b_dt,hw_c_dt)
data_dt2 <- rbind(hw_b_dt,hw_i_dt)
data_dt3 <- rbind(hw_c_dt,hw_i_dt)

plot_type(data_dt1,"IO","Measured IO (Baseline vs Collective)","Size")

plot_type(data_dt1,"Setup","Measured Setup (Baseline vs Collective)","Size")

plot_type(data_dt1,"Compute","Measured Compute (Baseline vs Collective)","Size")

plot_type(data_dt1,"MPI","Measured MPI (Baseline vs Collective)","Size")

plot_type(data_dt1,"Total","Measured Total (Baseline vs Collective)","Size")

plot_type(data_dt2,"IO","Measured IO (Baseline vs Parallel IO)","Size")

plot_type(data_dt2,"Setup","Measured Setup (Baseline vs Parallel IO)","Size")

plot_type(data_dt2,"Compute","Measured Compute (Baseline vs Parallel IO)","Size")

plot_type(data_dt2,"MPI","Measured MPI (Baseline vs Parallel IO)","Size")

plot_type(data_dt2,"Total","Measured Total (Baseline vs Parallel IO)","Size")

plot_type(data_dt1,"IO","Measured IO (Baseline vs Collective)","Processes")

plot_type(data_dt1,"Setup","Measured Setup (Baseline vs Collective)","Processes")

plot_type(data_dt1,"Compute","Measured Compute (Baseline vs Collective)","Processes")

plot_type(data_dt1,"MPI","Measured MPI (Baseline vs Collective)","Processes")

plot_type(data_dt1,"Total","Measured Total (Baseline vs Collective)","Processes")

plot_type(data_dt2,"IO","Measured IO (Baseline vs Parallel IO)","Processes")

plot_type(data_dt2,"Setup","Measured Setup (Baseline vs Parallel IO)","Processes")

plot_type(data_dt2,"Compute","Measured Compute (Baseline vs Parallel IO)","Processes")

plot_type(data_dt2,"MPI","Measured MPI (Baseline vs Parallel IO)","Processes")

plot_type(data_dt2,"Total","Measured Total (Baseline vs Parallel IO)","Processes")

plot_type(data_dt3,"IO","Measured IO (Collective vs Parallel IO)","Size")

plot_type(data_dt3,"Setup","Measured Setup (Collective vs Parallel IO)","Size")

plot_type(data_dt3,"Compute","Measured Compute (Collective vs Parallel IO)","Size")

plot_type(data_dt3,"MPI","Measured MPI (Collective vs Parallel IO)","Size")

plot_type(data_dt3,"Total","Measured Total (Collective vs Parallel IO)","Size")

plot_type(data_dt3,"IO","Measured IO (Parallel IO vs Collective)","Processes")

plot_type(data_dt3,"Setup","Measured Setup (Parallel IO vs Collective)","Processes")

plot_type(data_dt3,"Compute","Measured Compute (Parallel IO vs Collective)","Processes")

plot_type(data_dt3,"MPI","Measured MPI (Parallel IO vs Collective)","Processes")

plot_type(data_dt3,"Total","Measured Total (Parallel IO vs Collective)","Processes")